package com.jml.t1;

import kafka.producer.Partitioner;
import kafka.utils.VerifiableProperties;

public class HashPartitioner implements Partitioner {

    public HashPartitioner(VerifiableProperties verifiableProperties) {
    }

    @Override
    public int partition(Object key, int numPartiotion) {
        if (key instanceof Integer) {
            return Math.abs(Integer.parseInt(key.toString())) % numPartiotion;
        }
        return Math.abs(key.hashCode() % numPartiotion);
    }
}
